<template>
	<view>
		<image src="https://tzdj.1qit.com/assets/wx_imgs/my/addWx.png" mode="widthFix" class="w-300 addWxImg"></image>
		<image src="https://tzdj.1qit.com/assets/wx_imgs/index/index_banner.png" class="w-750 h-450"></image>
		<view class="index-box w-750">
			<info></info>
			<selects :list="list" @select="select" :keys="key"></selects>
			<view class="sure-btn w-600 h-80 t_c lh-80 c_bai f-30 br-50 m-l-75 m-r-75 m-t-200" @click="btnClick">
				确认选择
			</view>
		</view>
	</view>
</template>

<script>
	import info from './componetns/info.vue'
	import selects from './componetns/select.vue'
	export default {
		components:{
			info,selects
		},
		data() {
			return {
				key:0,
				list:[
					{
						title:"我是司机",
						desc:"选择司机",
						image:'https://tzdj.1qit.com/assets/wx_imgs/index/siji.png'
					},
					{
						title:"我是车主",
						desc:"选择车主",
						image:'https://tzdj.1qit.com/assets/wx_imgs/index/chezhu.png'
					}
				]
			}
		},
		onLoad() {
			console.log(this.$store.state.loginStatic)
		},
		onShow(){
			this.handleAuthorize()
		},
		methods: {
			async btnClick(){
				if(this.$store.state.loginStatic){
					if(this.key){
						uni.setStorageSync('identity',0)
						await this.$request.post('/api/common/swich',{identity:0})
						uni.redirectTo({
							url:"/pages/carOwner/releaseOrderIndex/index"
						})
					}else{
						uni.setStorageSync('identity',1)
						await this.$request.post('/api/common/swich',{identity:1})
						uni.redirectTo({
							url:"/pages/driver/receiveOrder/index"
						})
					}
				}else{
					uni.navigateTo({
						url:"/pages/login/index"
					})
				}
			},
			select(key){
				this.key = key
			},
			handleAuthorize() {
				const _this = this 
				uni.authorize({
					scope: 'scope.userLocation', 
					success(res) {
						console.log('已授权')
					},
					fail(err) {
						err = err['errMsg']
						uni.showModal({
							title: '重要提示',content: '如要使用小程序内核心功能，必须授权!',
							showCancel: false,
							confirmText: '确认授权'
						}).then(res => {
							if(res[1]['confirm']) {
								uni.openSetting({
									success(res) {
										console.log(res)
									}
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.addWxImg{
		position:absolute;
		right:20rpx;
		top:calc(var(--status-bar-height) + 90rpx);
	}
	.remind{
		background:rgba(0,0,0,.7);
		position:fixed;
		top:120rpx;
		right:30rpx;
		color:#fff;
	}
	.index-box{
		position:absolute;
		top:var(--status-bar-height);
		left:0;
		.sure-btn{
			background:#0055fe;
		}
	}
</style>
